package com.uenpay.oem.ui.reserver;

import android.text.TextUtils;

import com.uenpay.oem.data.modelImpl.BankCardModel;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.util.common.PicUtil;
import com.uenpay.util.net.listener.HttpOnNextListener;

/**
 * Created by DELL on 2017/6/20.
 */

public class AddnewcardPresenter implements AddnewcardContract.Pesenter {
    private AddnewcardContract.View mView;
    private BankCardModel mModel;
    private HttpOnNextListener<BankCardInfo> listener = new HttpOnNextListener<BankCardInfo>() {
        @Override
        public void onStart() {
            super.onStart();
            mView.showLoading();
        }

        @Override
        public void onNext(BankCardInfo info) {
            mView.setData(info);
            mView.dismissLoading();
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            mView.dismissLoading();
        }

        @Override
        public void onComplete() {
            super.onComplete();
            mView.dismissLoading();
        }
    };


    public AddnewcardPresenter(AddnewcardContract.View view){
        mView = view;
    }
    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public boolean checkData(String...data) {
        if(TextUtils.isEmpty(data[0])){
            mView.showToast("持卡人不能为空");
            return false;
        }
        if (TextUtils.isEmpty(data[1])) {
            mView.showToast("银行卡号不能为空");
            return false;
        }
        getCardInfo(data[1]);//获取卡号信息
        return true;
    }

    private void getCardInfo(String num){
        mModel = new BankCardModel();
        mModel.userBankCardBinSelect(num,listener);
    }



}
